﻿@using ZX.Tools
@using ZX.Model
@model MyCostBill
@{
    Sys_UserModel user = ViewBag.User;
    List<Approval_Log> listLog = ViewBag.ListLog ?? new List<Approval_Log>();
    string[] descs = (Model.ADesc + "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
    //List<Approval_User> listAuser = ViewBag.ListAUser ?? new List<Approval_User>();
    List<Approval> listApproval = ViewBag.ListApproval ?? new List<Approval>();
}
<div class='row page-content'>
    <div class='panel'>
        <div class='panel-heading'><strong><i class='icon-building'></i>费用报销单</strong></div>
        <div class='panel-body'>
            <form action="/MyCostBill/SaveData" method="post" class="form" id="formMyCostBill">
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="Status" value="@Model.Status" />
                <table class='table table-bordered' style="border: 1px solid #ddd;">
                    <tr>
                        <th class='text-center w-50px'>申请部门</th>
                        <td>
                            @user.DeptName
                        </td>
                        <th class="text-center w-120px">申请人</th>
                        <td>
                            @user.RealName
                        </td>
                        <th class='text-center w-100px'>日期</th>
                        <td>
                            @(Model.AddTime.ToDateFormat("yyyy-MM-dd"))
                        </td>
                    </tr>
                    <tr>
                        <th class="text-center w-130px">用途<span style="color:red">*</span></th>
                        <td colspan="3">
                            <ul id="ullist">
                                @for (int i = 0; i < descs.Length; i++)
                                {
                                    <li>

                                        <span>@(i + 1).</span>
                                        <input name="ADesc" type="text" style="width:80%;border:0;border-bottom:1px solid #ddd;height:35px;padding-bottom:0;padding-left:10px;" datatype="*" nullmsg="请填写事项" value="@descs[i]" />
                                        @if (i == descs.Length - 1)
                                        {
                                            <i class="icon icon-plus-sign-alt" style="cursor:pointer;" title="新增" onclick="onAddOrDelRow(this)"></i>
                                        }
                                        else
                                        {
                                            <i class="icon icon-minus-sign-alt" style="cursor:pointer;" title="删除" onclick="onAddOrDelRow(this)"></i>
                                        }

                                    </li>
                                }
                                @if (descs.Length == 0)
                                {
                                    <li>
                                        <span>1.</span>
                                        <input name="ADesc" type="text" style="width:80%;border:0;border-bottom:1px solid #ddd;height:35px;padding-bottom:0;padding-left:10px;" datatype="*" nullmsg="请填写事项" />
                                        <i class="icon icon-plus-sign-alt" style="cursor:pointer;" title="新增" onclick="onAddOrDelRow(this)"></i>
                                    </li>
                                }
                            </ul>
                        </td>
                        <th class="text-center w-60px">预计费用</th>
                        <td>
                            <input name="TotalMoney" style="width:100px;" class="form-control" value="@Model.TotalMoney" datatype="*" nullmsg="请填写预计费用"
                                   onkeypress="$.admin.keyPress(this)"
                                   onkeyup="$.admin.keyUp(this)"
                                   onblur="$.admin.keyBlur(this)" />
                        </td>
                    </tr>
                    <tr>
                        <th class='text-center w-50px'>原借款</th>
                        <td>
                            <input name="Advance" style="width:100px;" class="form-control" value="@Model.Advance" onkeypress="$.admin.keyPress(this)"
                                   onkeyup="$.admin.keyUp(this)"
                                   onblur="$.admin.keyBlur(this)" />
                        </td>
                        <th class="text-center w-120px">退/补</th>
                        <td>
                            <input name="Retrieve" style="width:100px;" class="form-control" value="@Model.Retrieve" onkeypress="$.admin.keyPress(this)"
                                   onkeyup="$.admin.keyUp(this)"
                                   onblur="$.admin.keyBlur(this)" />
                        </td>
                    </tr>
                    <tr>
                        <th class='text-center w-50px'>报销人</th>
                        <td>
                            <input name="ReimburseUser" style="width:100px;" class="form-control" value="@Model.ReimburseUser" />
                        </td>
                        <th class="text-center w-120px">领款人</th>
                        <td>
                            <input name="ReceiveUser" style="width:100px;" class="form-control" value="@Model.ReceiveUser" />
                        </td>
                    </tr>
                    @if (listLog.Count > 0)
                    {
                        <tr>
                            <th class="text-center w-120px">审批日志</th>
                            <td colspan="5">
                                <table>
                                    @foreach (var item in listLog)
                                    {
                                        <tr>
                                            <td style="border:0;">@(item.LContent + "，" + item.CreateTime.ToDateFormat("yyyy-MM-dd HH:mm:ss"))</td>
                                        </tr>
                                    }
                                </table>
                            </td>
                        </tr>
                    }
                    @*@if (listAuser.Count > 0)
                        {
                            <tr>
                                <th>请选择审批人</th>
                                <td colspan='9'>
                                    <select class="form-control" style="width:200px;" name="FK_ApprovalUserId" datatype="*" nullmsg="请选择审批人">
                                        <option value="">==请选择==</option>
                                        @foreach (var item in listAuser)
                                        {
                                            <option value="@item.Id" @(Model.FK_ApprovalUserId == item.Id ? "selected" : "")>@item.FlowName</option>
                                        }
                                    </select>
                                </td>
                            </tr>
                        }*@
                    <tr>
                        <th>请选择审批流程<span style="color:red">*</span></th>
                        <td colspan='5'>
                            <select class="form-control" style="max-width:80%;" name="FK_ApprovalId" datatype="*" nullmsg="请选择审批流程">
                                <option value="">==请选择==</option>
                                @foreach (var item in listApproval)
                                {
                                    <option value="@item.Id" @(Model.FK_ApprovalId == item.Id ? "selected" : "")>@item.DName</option>
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <td colspan='5'>
                            <a href='javascript:;' class='btn btn-primary' onclick='saveCaogao()'>存为草稿</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-primary' onclick='saveData()'>提交</a>
                            &nbsp;&nbsp;
                            <a href='javascript:;' class='btn btn-back' onclick='goBack()'>返回</a>
                            <span id="spmsg"></span>
                        </td>
                    </tr>
                </table>
                <input type="hidden" id="submitMsg" value="" />
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    var rowIndex = parseInt("@(descs.Length+1)");
    $(function () {
        $("#formMyCostBill").Validform({
            tiptype: function (msg, o, cssctl) {
                var objtip = $("#spmsg");
                cssctl(objtip, o.type);
                objtip.text(msg);
            },
            callback: function (form) {
                if ($("input[name='Status']").val() == "@ApplyStatus.草稿.ToInt()") {
                    win.showLoading("正在保存...");
                    $("#formMyCostBill").ajaxSubmit(function (data) {
                        if (data.Code == 300) {
                            win.alert(data.Message);
                        } else if (data.Code == 200) {
                            win.success($("#submitMsg").val(), function () {
                                goBack();
                            }, 1000);
                        }
                    });
                } else {
                    win.confirm("确认提交审批？", function () {
                        win.showLoading("正在保存...");
                        $("#formMyCostBill").ajaxSubmit(function (data) {
                            if (data.Code == 300) {
                                win.alert(data.Message);
                            } else if (data.Code == 200) {
                                win.success($("#submitMsg").val(), function () {
                                    goBack();
                                }, 1000);
                            }
                        });
                    });
                }
                return false;
            }
        });
    });
    function saveCaogao() {
        $("input[name='Status']").val("@(ApplyStatus.草稿.ToInt())");
        $("#submitMsg").val("保存草稿成功");
        $("#formMyCostBill").submit();
    }
    function saveData() {
        if(@Model.Id==0||@Model.Status==4)$("input[name='Status']").val("@(ApplyStatus.新申请.ToInt())");
        $("#submitMsg").val("提交审批成功");
        $("#formMyCostBill").submit();
    }
    function goBack() {
        window.history.go(-1);
    }
    //新增行
    function onAddOrDelRow(obj) {
        if ($(obj).attr("title") == "新增") {
            if (rowIndex == 1) rowIndex++;
            var newTr = $(obj).parent().clone();
            $(newTr).find("span").html(rowIndex + ".");
            $(newTr).find("input").val("");
            $("#ullist").append(newTr);
            $(obj).removeClass("icon-plus-sign-alt").addClass("icon-minus-sign-alt").attr("title", "删除");
            rowIndex++;
        } else {
            $(obj).parent().remove();
        }
    }
</script>
